﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using GalaSoft.MvvmLight.Messaging;
using ViewModel.Rss;


namespace EPIClientRssWP7
{
    public partial class ItemRssListView : PhoneApplicationPage
    {
        RssViewModel vm;
        public ItemRssListView()
        {
            InitializeComponent();
            //Messenger.Default.Register<Uri>(this, "NavigationItemChosen", (uri) => {
				
            //});
           vm = this.DataContext as RssViewModel;
           Messenger.Default.Register<Uri>(this, "NavigationItemChosen", (paquet) =>
            {
                NavigationService.Navigate(paquet);
            });
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            //if (vm != null)
            //    vm.ItemSelected = null;
        }

        protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            if (!(this.DataContext is RssViewModel))
                return;
            var vm = this.DataContext as RssViewModel;
            if (vm.CanExecuteSetReaded() == true)
                vm.ExecuteSetReaded();
            base.OnNavigatingFrom(e);
        }

        private void bar_reload(object sender, System.EventArgs e)
        {
        	 if (!(this.DataContext is RssViewModel))
                return;
            var vm = this.DataContext as RssViewModel;
            if (vm.CanExecuteReload() == true)
                vm.ExecuteReload();
        }
    }
}
